﻿using PollSystemService;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using Microsoft.VisualStudio.TestTools.UnitTesting.Web;
using System.Net;
using System.Text;
using System.Text.RegularExpressions;

namespace TestProject1
{
    [TestClass()]
    public class PollSystemServiceTest
    {
        [TestMethod()]
        [UrlToTest("http://localhost:2709/")]
        public void VoteForAnswerAndGetVotesCountTest()
        {
            PollSystemService.PollSystemService target = new PollSystemService.PollSystemService(); // TODO: Initialize to an appropriate value

            AnswerDTO answer = target.GetAnswers()[0];
            var resultAnswers = target.VoteForAnswerAndGetVotesCount(answer.AnswerId.ToString());
            AnswerDTO resultAnswer = null;

            for (int i = 0; i < resultAnswers.Length; i++)
            {
                if (resultAnswers[i].AnswerId == answer.AnswerId)
                {
                    resultAnswer = resultAnswers[i];
                    break;
                }
            }

            bool countIncreased = resultAnswer.VotesCount > answer.VotesCount;

            Assert.IsTrue(countIncreased);
        }

        [TestMethod()]
        [UrlToTest("http://localhost:2709/")]
        [ExpectedException(typeof(FormatException))]
        public void VoteForAnswerAndGetVotesCountTest_InvalidArgs()
        {
            PollSystemService.PollSystemService target = new PollSystemService.PollSystemService(); // TODO: Initialize to an appropriate value           
            target.VoteForAnswerAndGetVotesCount("ala_bala");            
        }

        [TestMethod()]
        [UrlToTest("http://localhost:2709/")]
        [ExpectedException(typeof(InvalidOperationException))]
        public void VoteForAnswerAndGetVotesCountTest_InvalidArgs2()
        {
            PollSystemService.PollSystemService target = new PollSystemService.PollSystemService(); // TODO: Initialize to an appropriate value           
            target.VoteForAnswerAndGetVotesCount("0");            
        }
    }    
}
